<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="UTF-8" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <title>VUE3初体验-计数器</title>
  </head>
  <body>
    <div id="app"></div>

    <!-- template 标签是由 HTML5 提供的 -->
    <template id="tpl">
      <div>
        <h2>{{counter}}</h2>
        <button @click="increment">+1</button>
        <button @click="decrement">-1</button>
      </div>
    </template>

    <script src="https://unpkg.com/vue@3/dist/vue.global.js"></script>
    <script>
      const app = Vue.createApp({
        template: "#tpl",
        setup() {
          const counter = Vue.ref(0);

          const increment = () => {
            counter.value++;
          };

          const decrement = () => {
            counter.value--;
          };

          return {
            counter,
            increment,
            decrement,
          };
        },
      });
      app.mount("#app");
    </script>
  </body>
</html>
